-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix cover matrix alignment #28404
Fix cover matrix alignment #28404
Conversation
a599338
to
21dfbb7
Compare
Thanks @ajlende! This is looking good to me; I can confirm that I'm not seeing the glitch I was seeing with #28361, nor the one I was seeing with #28365. I'll do some more testing... |
Looking at the code, I like this fix more than mine. And forgive me for stating the obvious, but we should only merge one of the two 😅 |
// Extra specificity for in edit mode where other styles would override it otherwise. | ||
img.wp-block-cover__image-background, | ||
video.wp-block-cover__video-background { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need the img
and video
element-based selectors? 😅 I was hoping that moving the selectors into .wp-block-cover
would be specific enough.
// Extra specificity for in edit mode where other styles would override it otherwise. | |
img.wp-block-cover__image-background, | |
video.wp-block-cover__video-background { | |
.wp-block-cover__image-background, | |
.wp-block-cover__video-background { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wasn't working for me without it, unfortunately. Without it, the specificity is the same and these styles don't get applied.
edit: for the record, the selector that I needed to override was .editor-styles-wrapper img
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the extra specificity is only needed in the editor, I could duplicate these styles in edit.scss with the extra specificity and move these out to where they were before. But, I figured it would be better to avoid duplication between edit and save wherever possible.
Some visual differences on the frontend with Twenty Twenty. This PR: |
I think my last change may have fixed that too. Give it a try |
Oh wow, looks like! 🎉 |
I think I should start creating a test matrix to keep track of the tricky ones:
Known problematic cases:
@ajlende Am I missing anything? |
My testing hasn't made it back past Twenty Nineteen yet, but for the things that I have tested so far, that's a complete list |
I've covered all the Twenties now (although I didn't go through all alignments for each of them), and things are looking good 🎉 It's getting late here, and I'd like to have @jasmussen take a final look at this to weigh in on the CSS changes (and maybe give it some more testing). If all goes well, I'll merge tomorrow (and will release 9.8.1). |
I'm sitting here in GMT-10 so I have a lot of daylight left. I'll have something ready for you and Joen in the morning. Found one bug with the focal point picker in Twenty Twenty edit: It's not a bug with the theme, edit2: Now the bug is showing up with other alignments as well. Maybe a JS thing, more investigation is needed. |
I don't know if it is the same thing you're seeing but I just made #28406 to fix an issue I've been seeing with the Focal point picker. |
@stokesman That's exactly the issue. I was wondering if it might be related because I moved a piece of code that said, "This explicit height rule is necessary for the focal point picker to work." Based on the other CSS I have it doesn't seem like that line is useful, so I might remove it and then test a bunch to confirm. |
@stokesman and @ajlende, I added that line:
I added it when I restored the |
@@ -4,8 +4,6 @@ | |||
background-size: cover; | |||
background-position: center center; | |||
min-height: 430px; | |||
width: 100%; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This rule was moved from style.scss to editor.scss, which makes me nervous. In general, unless it's explicitly for block editor specific shenanigans, like extra divs, adjacent markup, or visuals that appear only in the editor, my instinct is to keep as much of the CSS as possible in style.scss. That way any visual issues you fix on the frontend, you also fix in the editor.
I might move this back, but I need to test a little bit more first.
Alright, I'm taking a deep dive this morning, and already now I have a few high level thoughts to share: First off, this PR is good and short. We can potentially make it simpler, I left a comment, but the basics seem correct. In testing the various twenties, it seems additionally clear that the change from a CSS background to an Because of those adjacent issues, we might want to strengthen some selectors and add additional rules. But I'm not sure whether that's something for this PR or something best to keep separate. Specifically, Twenty Eleven is a great theme to test, because it has pretty elaborate rules that target the A 1px white gray border, padding, and more. This PR gets closer in addressing that, but it doesn't get all the way: As far as I'm aware, the only way to prevent this CSS bleed is to use
What other things might a theme do? Box-shadow? Outlines? CSS filters? Is there ever an edgecase where we would want to allow a theme's image styles to bleed into the cover, or do we have to treat the img as purely a dumb element? I'm nervous about going down this nuclear road, but it seems clear from testing that it's an arms race now that the |
Alright, I pushed a change to move the height rule back to the style.scss file, and to add a bunch of extra properties to unset, trying to pre-empt what might bleed in from a theme. That effectively makes this PR identical to #28412, except softer: the rules have high specificity, but not "nuclear" (there are no !importants). And it solves the TwentyEleven theme case: I think this is good enough to merge as a fix, and we can always look at whether we need to increase the specificity here. |
Let me take a look at that one. Maybe it was the moving of the 100% height, after all. |
Yeah, it appears that height: 100%; needs to be in the editor only. Even there, I'd still like to remove it, and #28406 might be our opportunity to do that. But that's for another day. Before: After: Also rebased. |
Thanks Joen! ❤️ |
c501fb3
to
2543962
Compare
Okay I'm not sure I rebased that right, but it wasn't strictly necessary, and the branch appears to work as intended still. |
Wow that's a good catch! That's a pre-existing issue, and appears to be a bug with the demo content, no less. Specifically, the demo content has both align center, and align wide applied, which takes on the frontend but not in the editor. If you delete the cover block from the demo content, and create a fresh one, then align it wide or center in however direction you want to go, it works fine, both in the editor and published. |
Hmm, interesting. So it seems like the block has the <!-- wp:cover {"url":"https://cldup.com/Fz-ASbo2s3.jpg","className":"alignwide"} -->
<div class="wp-block-cover has-background-dim alignwide"><img class="wp-block-cover__image-background" alt="" src="https://cldup.com/Fz-ASbo2s3.jpg" data-object-fit="cover"/><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"align":"center","placeholder":"Write title…","fontSize":"large"} -->
<p class="has-text-align-center has-large-font-size">Of Mountains & Printing Presses</p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:cover --> Then, when I set the alignment to <!-- wp:cover {"url":"https://cldup.com/Fz-ASbo2s3.jpg","align":"center","className":"alignwide"} -->
<div class="wp-block-cover aligncenter has-background-dim alignwide"><img class="wp-block-cover__image-background" alt="" src="https://cldup.com/Fz-ASbo2s3.jpg" data-object-fit="cover"/><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"align":"center","placeholder":"Write title…","fontSize":"large"} -->
<p class="has-text-align-center has-large-font-size">Of Mountains & Printing Presses</p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:cover --> So now we have Not sure this is a bug with the demo content though. It looks a bit like it's a block migration that's not working properly maybe? (Anyway, not directly related to this PR. Just noting here FTR and a later fix.) |
Yep, there's some weirdness there, but all of that I reproduced in the main branch, so no blockers for this one, I'd say. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I've given another round of testing to the known troublemakers, and they're looking good now 👍
Co-authored-by: jasmussen <joen@automattic.com>
Cherry-picked to |
Description
Fixes cover block positioning when the text align matrix is used. Similar to #28365, but I was still having some issues on save with positioning without adding the height.
I collapsed the fix that was used in edit into save to resolve that positioning issue.
How has this been tested?
Screenshots
Edit Before
Edit After
Save Before
Save After
Types of changes
Bug fix
Checklist: